using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Config = Dimok.Config;
using Dimok.Data;
using Dimok.Data.Database;

namespace Dimok.Menu.Admin{

	////////////////////////////////////////////////////////////////////////////////////////////////////
	/// <summary>	Work flow. </summary>
	///
	/// <remarks>	Dimon, 12/21/2010. </remarks>
	////////////////////////////////////////////////////////////////////////////////////////////////////

	public class WorkFlow : System.Web.UI.Page{
		protected Literal ltrWF;
		protected Literal ltrWFG;
		protected HtmlSelect selWF_MenuFrom;
		protected HtmlSelect selWF_MenuTo;
		protected HtmlSelect selWFG_MenuFrom;
		protected HtmlSelect selWFG_MenuTo;
		protected HtmlSelect selGroups;

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	Event handler. Called by Page for load events. </summary>
		///
		/// <remarks>	Dimon, 12/21/2010. </remarks>
		///
		/// <param name="sender">	Source of the event. </param>
		/// <param name="e">			Event information. </param>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		private void Page_Load(object sender, System.EventArgs e){
			WS ws = new WS();
			UserObjectEx uox = new UserObjectEx();
			ltrWF.Text = ws.WF_Get();
			ltrWFG.Text = ws.WFG_Get();
			DataSet dsMenus = SQLHelperEx.ExecuteDatasetEx(uox.db,"SELECT MenuID,MenuPath FROM v_Menu_WorkFlow");
			FillHTMLSelect(selWF_MenuFrom,dsMenus,"MenuID","MenuPath");
			FillHTMLSelect(selWF_MenuTo,dsMenus,"MenuID","MenuPath");
			FillHTMLSelect(selWFG_MenuFrom,dsMenus,"MenuID","MenuPath");
			FillHTMLSelect(selWFG_MenuTo,dsMenus,"MenuID","MenuPath");
			//FillHTMLSelect(selGroups,SQLHelperEx.ExecuteDatasetEx(uox.db,"SELECT GroupName FROM t_Groups ORDER BY GroupName"),"GroupName","GroupName");
			ADsGroupDS dsGroups = uox.GetAllGroupsInNamespace();
			foreach( string winNTGroup in Config.application.WinNTGroups.Split(',') )
				if( dsGroups.t_Group.Select("cn='"+winNTGroup+"'").Length == 0 )
					dsGroups.t_Group.Addt_GroupRow("","Admin","","");
			//dsGroups.t_Group.Addt_GroupRow("","Super","");
			FillHTMLSelect(selGroups,dsGroups,"cn","cn");
		}

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	Fill html select. </summary>
		///
		/// <remarks>	Dimon, 12/21/2010. </remarks>
		///
		/// <param name="sel">					The selected. </param>
		/// <param name="ds">						The ds. </param>
		/// <param name="valueColumn">	The value column. </param>
		/// <param name="textColumn">		The text column. </param>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		private void FillHTMLSelect(HtmlSelect sel,DataSet ds,string valueColumn,string textColumn){
			sel.DataSource = ds;
			sel.DataValueField = valueColumn;
			sel.DataTextField = textColumn;
			sel.DataBind();
		}
		#region Web Form Designer generated code

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	Raises the initialise event. </summary>
		///
		/// <remarks>	Dimon, 12/21/2010. </remarks>
		///
		/// <param name="e">	Event information to send to registered event handlers. </param>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	
		/// Required method for Designer support - do not modify the contents of this method with the code
		/// editor. 
		/// </summary>
		///
		/// <remarks>	Dimon, 12/21/2010. </remarks>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);
		}
		#endregion
	}
}
